<?php 
class FlinkController extends CommonController{
	//添加方法
	public function add(){
		if(IS_POST){
			// p($_POST);
			$_POST['addtime']=time();
			$upload = new upload();
			$uplofiles =$upload->upload();
			// p($uplofiles);
			$_POST['logo']=$uplofiles[0]['path'];
			// p($_POST);
			$model=M('Flink');
			$re=$model->add($_POST);
			if($re){
				$this->success('添加成功','Flink/index');
			}else{
				$this->success('添加失败','Flink/index');
			}
		}else{
			$this->display();
		}
	}

	//显示
	public function index(){
		if(IS_POST){
			//此处是排序与分类排序一样
			p($_POST);

		}else{

			$model=M('Flink');
			$FlinkData=$model->all();
			// p($FlinkData);
			
			$this->assign('FlinkData',$FlinkData);
			$this->display();
		}
	}
	//修改
	public function edit(){

		$model=M('Flink');
		if(IS_POST){
			// p($_POST);
			// p($_FILES);
			// 如果$_FILES不为空代表用户上传了新图片
			if(!empty($_FILES)){
				// 第一步：我们要删除旧图片
				unlink($_POST['logo']);

				// 第二部我们要上传新图片，并保存新图片的路径到$_POST中
				$upload = new upload();
				$uplofiles =$upload->upload();
				// p($uplofiles);
				$_POST['logo']=$uplofiles[0]['path'];
			}

				// p($_POST);die;
				$re=$model->where(array('fid'=>$_POST['fid']))->save($_POST);
				if($re){
					$this->success('修改成功','Flink/index');
				}else{
					$this->success('修改失败','Flink/index');
				}

		}else{
			// p($_GET);die;
			$fid=$_GET['fid'];
			$curData=$model->where(array('fid'=>$fid))->all();
			// p($curData);
			$this->assign('curData',$curData);
			// echo $fid;
			$this->display();
		}
	}

	//删除方法 
	public function del(){
		$fid=intval($_GET['fid']);
		$flink=M('Flink');
		$re=$flink->where(array('fid'=>$fid))->del();
		if($re){
			$this->success('删除成功',U('Flink/index'));
		}else{
			$this->error('删除失败',U('Flink/index'));
		}
	}
}

 ?>